package com.orphan.util.mqConfig;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class PurchaseMq {
    //注入工厂（已经预加载）
    @Autowired
    CachingConnectionFactory cachingConnectionFactory;
    //rabbitmq模板
//    @Bean(value = "rabbitTemplate")
//    public RabbitTemplate rabbitTemplate(){
//        return new RabbitTemplate(cachingConnectionFactory);
//    }
    //创建队列
    @Bean
    public Queue queue1(){
        return new Queue("queue1");
    }
    //创建默认交换机
    @Bean
    public DirectExchange directExchange1(){
        return new DirectExchange("directExchange1" );
    }
    //把队列绑定到交换机
    @Bean
    public Binding purchaseOrderToDirectExchange(Queue queue1, DirectExchange directExchange1){
        return BindingBuilder.bind(queue1).to(directExchange1).with("one");
    }
}
